package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Claimresult;
import cn.wolfcode.crm.query.ClaimresultObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IClaimresultService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("claimresult")
public class ClaimresultController {
    @Autowired
    private IClaimresultService claimresultService;

    @RequiresPermissions("claimresult:index")
    @PermissionName("赔付主页")
    @RequestMapping("index")
    public String index(@ModelAttribute("qo") ClaimresultObjectQuery qo) {
        return "claimresult/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult<Claimresult> list(@ModelAttribute("qo") ClaimresultObjectQuery qo) {
        PageResult<Claimresult> result = claimresultService.query(qo);
        return result;
    }

    @RequestMapping("query")
    @ResponseBody
    public List<Claimresult> query() {
        return claimresultService.getAll();
    }

    @RequiresPermissions("claimresult:save")
    @PermissionName("赔付核价")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Claimresult claimresult) {
        JsonResult jsonResult = new JsonResult();
        try {
            claimresultService.save(claimresult);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.markErrorMsg("核损明细创建失败");
        }
        return jsonResult;
    }

    @RequiresPermissions("claimresult:getDetailByInsurerId")
    @RequestMapping("getDetailByInsurerId")
    @ResponseBody
    public Claimresult getDetailByInsurerId(Long insurerId) {

        return claimresultService.getDetailByInsurerId(insurerId);
    }
}
